package com.chinawayltd.ews.sample.service.task.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.chinawayltd.ews.sample.mapper.TTaskNodeMapper;
import com.chinawayltd.ews.sample.mapper.task.TaskNodeExtendMapper;
import com.chinawayltd.ews.sample.model.TTaskNode;
import com.chinawayltd.ews.sample.model.task.TaskMaterielVO;
import com.chinawayltd.ews.sample.model.task.TaskNodeVO;
import com.chinawayltd.ews.sample.model.task.TaskOrderNodeVO;
import com.chinawayltd.ews.sample.service.task.TaskNodeService;

/**
 * @program: greeProject
 * @description 运输任务节点管理service
 * @author: chenxin
 * @create: 2018年4月27日 下午6:07:21
 */
@Service
public class TaskNodeServiceImpl implements TaskNodeService {

	@Autowired
	private TaskNodeExtendMapper taskNodeExtendMapper;
	
	@Autowired
	private TTaskNodeMapper tTaskNodeMapper;
	

	@Override
	public List<TaskNodeVO> getTaskNodeList(Long taskId) throws Exception{
		return taskNodeExtendMapper.getTaskNodeList(taskId);
	}

	@Override
	public List<TaskMaterielVO> getTaskMaterielListByBranchId(String[] ids, Long startPlaceId) throws Exception{
		return taskNodeExtendMapper.getTaskMaterielListByBranchId(ids, startPlaceId);
	}

	@Override
	public List<TaskMaterielVO> getTaskMaterielListByNodeId(Long nodeId) throws Exception{
		return taskNodeExtendMapper.getTaskMaterielListByNodeId(nodeId);
	}

	@Override
	public TTaskNode getById(Long id) throws Exception{
		// 判断id是否为空
    	if(id == null || id <= 0){
            throw new RuntimeException("id不能为空或者少于等于0！");
        }
		return tTaskNodeMapper.selectByPrimaryKey(id);
	}

	@Override
	public List<TTaskNode> getBeforeNode(TTaskNode node) throws Exception {
		return taskNodeExtendMapper.getBeforeNode(node);
	}

	@Override
	public TaskNodeVO getTaskNodeVOById(Long nodeId) {
		return taskNodeExtendMapper.getTaskNodeVOById(nodeId);
	}

	@Override
	public List<TaskOrderNodeVO> getNodeOrderByNodeId(Long nodeId) throws Exception {
		return taskNodeExtendMapper.getNodeOrderByNodeId(nodeId);
	}

	@Override
	public List<TaskMaterielVO> getTaskMaterielListByNodeIdAndOrderId(Long nodeId, Long orderId) {
		return taskNodeExtendMapper.getTaskMaterielListByNodeIdAndOrderId(nodeId, orderId);
	}

	@Override
	public int deleteNoteByTaskId(Long id) throws Exception {
		return taskNodeExtendMapper.deleteNoteByTaskId(id);
		
	}

	@Override
	public List<TaskNodeVO> getOrderDetailByTaskAndBranch(Long taskId, String branchType) throws Exception {
		return taskNodeExtendMapper.getOrderDetailByTaskAndBranch(taskId, branchType);
	}

	@Override
	public List<TaskMaterielVO> getTaskMaterielListByNodeIds(String[] ids, String orderNo)  throws Exception {
		return taskNodeExtendMapper.getTaskMaterielListByNodeIds(ids, orderNo);
	}

	@Override
	public List<TTaskNode> getNoFinishNode(Long taskId) throws Exception {
		return taskNodeExtendMapper.getNoFinishNode(taskId);
	}

	@Override
	public int updateTaskNodeByNodeIdAndStatus(Integer i, Long id, Date date) throws Exception {
		Map<String, Object> map = new HashMap<>();
		map.put("statusNum", i);
		map.put("nodeId", id);
		map.put("updateTime", date);
		return taskNodeExtendMapper.updateTaskNodeByNodeIdAndStatus(map);
	}

	@Override
	public int completeTaskNodeByNodeIdAndStatus(Integer i, Long id, Date date) throws Exception {
		Map<String, Object> map = new HashMap<>();
		map.put("statusNum", i);
		map.put("nodeId", id);
		map.put("updateTime", date);
		return taskNodeExtendMapper.completeTaskNodeByNodeIdAndStatus(map);
	}

	@Override
	public int updateNodeExTendByNodeId(Long nodeId, Date date) throws Exception {
		Map<String, Object> map = new HashMap<>();
		map.put("nodeId", nodeId);
		map.put("updateTime", date);
		return taskNodeExtendMapper.updateNodeExTendByNodeId(map);
	}

	@Override
	public int completeNodeExTendByNodeId(Long nodeId, Date date) throws Exception {
		Map<String, Object> map = new HashMap<>();
		map.put("nodeId", nodeId);
		map.put("updateTime", date);
		return taskNodeExtendMapper.completeNodeExTendByNodeId(map);
	}

	@Override
	public int deleteTaskNoteExtendByTaskId(Long id) throws Exception {
		// 判断id是否为空
    	if(id == null || id <= 0){
            throw new RuntimeException("id不能为空或者少于等于0！");
        }
		return taskNodeExtendMapper.deleteTaskNoteExtendByTaskId(id);
	}

	@Override
	public int deleteNoteOrderByTaskId(Long id) throws Exception {
		// 判断id是否为空
    	if(id == null || id <= 0){
            throw new RuntimeException("id不能为空或者少于等于0！");
        }
		return taskNodeExtendMapper.deleteNoteOrderByTaskId(id);
	}

	@Override
	public void updateNodeActualFinishTimeByNodeId(Long nodeId, Date date) {
		Map<String, Object> map = new HashMap<>();
		map.put("nodeId", nodeId);
		map.put("updateTime", date);
		taskNodeExtendMapper.updateNodeActualFinishTimeByNodeId(map);
	}

	@Override
	public void completeTaskNodeByTaskIdAndNodeType(int i, Long taskId, Date date) {
		Map<String, Object> map = new HashMap<>();
		map.put("nodeType", i);
		map.put("taskId", taskId);
		map.put("updateTime", date);
		taskNodeExtendMapper.completeTaskNodeByTaskIdAndNodeType(map);
		
	}

	@Override
	public Map<String, Object> getNodeTotalLiftByNodeId(Long nodeId) {
		return taskNodeExtendMapper.getNodeTotalLiftByNodeId(nodeId);
	}

	
}
